package main

import (
	"WebLearning/web26/helloworld"
	"context"
	"google.golang.org/grpc"
	"log"
	"os"
	"time"
)

const (
	address     = "localhost:50051"
	defaultName = "world"
)

func main() {
	dial, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
	if err != nil {
		return
	}
	defer dial.Close()
	c := helloworld.NewGreeterClient(dial)
	// Contact the server and print out its response.
	name := defaultName
	if len(os.Args) > 1 {
		name = os.Args[1]
	}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	hello, err := c.SyayHello(ctx, &helloworld.HelloRequest{Name: name})
	if err != nil {
		return
	}
	log.Println(hello.Message)

}
